package com.itheima;

import com.itheima.Dao.BookDao;
import com.itheima.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 通过IOC容器获取对象，而不是new对象
 */
public class App2 {
    public static void main(String[] args) {
        //获取IOC容器:参数为applicationContext.xml配置文件，将配置文件中的对象加载到IOC容器中
        ApplicationContext IOC=new ClassPathXmlApplicationContext("applicationContext.xml");
        //获取bean,参数为配置文件中对象的id
        Object bookDao = IOC.getBean("bookDao");
        //将Object对象转为BookDao对象
        BookDao bookDao1= (BookDao) bookDao;
        //调用数据访问层的方法
        bookDao1.save();


        //获取BookService
        BookService service = (BookService) IOC.getBean("bookService");
        service.save();


    }
}
